package com.monitor.controller;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.zxing.WriterException;
import com.monitor.entity.*;
import com.monitor.service.*;
import com.monitor.util.DataUtil;
import com.monitor.util.QRcodeUtil;
import com.monitor.util.Result;
import com.monitor.util.WxPayUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/erpServiceOrderProject")
@Api(description="订单交易和发票关联")
public class ErpServiceProjectController {

    @Resource
    private ErpServiceProjectService erpServiceProjectService;
    @Resource
    private ErpProjectInServiceService erpProjectInServiceService;
    @Resource
    private ErpInvoiceService erpInvoiceService;
    @Resource
    private ErpProjectService erpProjectService;
    @Resource
    private ErpCustomerService erpCustomerService;
    @Resource
    private  ErpUserService erpUserService;


    @RequestMapping("/insertErpServiceOrder")
    @ApiOperation("通过费用编辑生成订单")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
//            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
        Result<ErpServiceProject> inertProjectOrder(String json) {//, HttpServletRequest request
//        JSON.parseObject(json, new TypeReference<List<实体类或其他泛型>>(){});

        Integer custId =0;

//        List<ErpProject> erpProjects = project.getErpProjects();
        //  List<ErpProject> erpProjects, Integer custId
//        JSONArray obj3 = JSON.parseArray(erpProjects.toString());
//        JSONObject obj = new JSONObject().fromObject(erpProjects);
        ErpServiceProject erpServiceProject=new ErpServiceProject();
        Result<ErpServiceProject> booleanResult=new  Result<ErpServiceProject>() ;
        try {
            List<ErpProject> erpProjects=new ArrayList<ErpProject>(JSONArray.parseArray(json,ErpProject.class));
//        ErpServiceProject project = JSON.parseObject(json, ErpServiceProject.class);

            for (int i = 0; i < erpProjects.size(); i++) {
                ErpProject erpProject =  erpProjects.get(i);
                custId =   erpProject.getCustId();
                if (custId!=0)
                    break;
            }
//            erpServiceProject.setUserId(custId);
            erpServiceProject.setUserId(custId);//Integer.parseInt(request.getSession().getId())   //先写1, 没办法测试
            SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
            String newDate=sdf.format(new Date());
            String result="";
            Random random=new Random();

            for(int i=0;i<3;i++){
                result+=random.nextInt(10);
            }
            Integer a=0;
            Integer b=0;
            erpServiceProject.setOrderId(newDate+result);
            for (int i = 0; i < erpProjects.size(); i++) {
                ErpProject erpProject =  erpProjects.get(i);

                a     =  erpProject.getProjectNum()*erpProject.getProjectMoney();
                b+=a;
            }
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            erpServiceProject.setDate(df.format(new Date()));// new Date()为获取当前系统时间

            erpServiceProject.setMoneySum(b+0.0);

            erpServiceProjectService.insert(erpServiceProject);
            ErpProjectInService erpProjectService =new ErpProjectInService();
            for (int i = 0; i < erpProjects.size(); i++) {
                ErpProject erpProject =  erpProjects.get(i);
                erpProjectService.setNumber(erpProject.getProjectNum());
                erpProjectService.setProjectId(erpProject.getId());
                erpProjectService.setService_project_id(erpServiceProject.getId());
                erpProjectService.setStartDate(df.format(new Date()));
                Integer number = erpProjectService.getNumber();
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date());//设置起时间
                cal.add(Calendar.YEAR, number);
                erpProjectService.setEndDate(df.format(cal.getTime()));
                Calendar calendar   =   new GregorianCalendar();
                calendar.setTime(new Date());
                if (erpProject.getId()==5){

                    calendar.add(calendar.DATE,erpProject.getProjectNum());//把日期往后增加x天.整数往后推,负数往前移动
                }else{
                    calendar.add(calendar.YEAR, erpProject.getProjectNum());//把日期往后增加x年.整数往后推,负数往前移动
                }
                erpProjectService.setOrderNumber(newDate+result);
                erpProjectInServiceService.insert(erpProjectService);
                booleanResult.setData(erpServiceProject);
                booleanResult.setMsg("添加订单成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            booleanResult.setData(erpServiceProject);
            booleanResult.setMsg("添加订单失败");
        }
        return  booleanResult;
    }
    @RequestMapping("/updateErpServiceOrder")
    @ApiOperation("修改订单")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Boolean> UpdateInsurance(ErpServiceProject erpServiceProject) {

        Result<Boolean> booleanResult=new  Result<Boolean>() ;
        try{
            boolean b = erpServiceProjectService.updateById(erpServiceProject);
            booleanResult.setMsg("修改成功");
            booleanResult.setData(true);
        }catch (Exception e ){
            e.printStackTrace();
        }
        return booleanResult;
    }
    @RequestMapping("/selectOrder")
    @ApiOperation("根据订单号查询订单")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
          @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<ErpServiceProject> selectOrder(String orderId) {

        Result<ErpServiceProject> booleanResult=new  Result<>() ;
        try{
            ErpServiceProject erpServiceProjects = erpServiceProjectService.selectOne(new EntityWrapper<ErpServiceProject>().eq("order_id",orderId));
            List<ErpProjectInService> order_number = erpProjectInServiceService.selectList(new EntityWrapper<ErpProjectInService>().eq("order_number", orderId));
            ErpCustomer erpCustomer = erpCustomerService.selectById(erpServiceProjects.getUserId());
            for (int i = 0; i < order_number.size(); i++) {
                ErpProjectInService erpProjectInService =  order_number.get(i);
                ErpProject erpProject = erpProjectService.selectById(erpProjectInService.getProjectId());
                erpProjectInService.setProjectName(erpProject.getProjectName());
                erpProjectInService.setCustName(erpCustomer.getCusName());
                erpProjectInService.setCustCode(erpCustomer.getCusCode());
            }
//            list.add(erpServiceProjects);
            erpServiceProjects.setErpProjectInServices(order_number);
            booleanResult.setMsg("查询成功");
            booleanResult.setData(erpServiceProjects);
        }catch (Exception e ){
            e.printStackTrace();
        }
        return booleanResult;
    }   @RequestMapping("/selectOrders")
    @ApiOperation("缴费统计")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
          @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpServiceProject>> selectOrders(Integer custId,String startDate,String endDate) throws  Exception {

        Result<List<ErpServiceProject>> booleanResult=new  Result<>() ;
        try{
            List<ErpServiceProject> erpServiceProjects = erpServiceProjectService.selectList(new EntityWrapper<ErpServiceProject>().eq("user_id",custId).between("date",startDate,endDate));
            erpServiceProjects.parallelStream().forEach(erpServiceProject->{

                ErpCustomer erpCustomer = erpCustomerService.selectById(erpServiceProject.getUserId());
                List<ErpProjectInService> order_number = erpProjectInServiceService.selectList(new EntityWrapper<ErpProjectInService>().eq("order_number", erpServiceProject.getOrderId()));
                order_number.parallelStream().forEach(erpProjectInService->{
                    if (order_number!=null){
//                        ErpProjectInService erpProjectInService =  order_number.get(j);
                        ErpProject erpProject = erpProjectService.selectById(erpProjectInService.getProjectId());
                        if (erpProject!=null){
                            erpProjectInService.setProjectName(erpProject.getProjectName());
                            erpProjectInService.setCustName(erpCustomer.getCusName());
                            erpProjectInService.setCustCode(erpCustomer.getCusCode());

                        }
                        erpServiceProject.setErpProjectInServices(order_number);

                    }
                });
//                for (int j = 0; j < order_number.size(); j++) {
//
//                }
            });
//                ErpServiceProject erpServiceProject =  erpServiceProjects.get(i);

//            }

//            list.add(erpServiceProjects);

            booleanResult.setMsg("查询成功");
            booleanResult.setData(erpServiceProjects);
        }catch (Exception e ){
            e.printStackTrace();
        }
        return booleanResult;
    }
   @RequestMapping("/selectYears")
    @ApiOperation("系统管理-系统年费")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
          @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpProjectInService>> selectYears(Integer custId) {

        Result<List<ErpProjectInService>> Result=new  Result<>() ;
        try{
            ErpCustomer erpCustomer = erpCustomerService.selectById(custId);
            List<ErpProjectInService>  a=new ArrayList<>();
            List<ErpServiceProject> user_id = erpServiceProjectService.selectList(new EntityWrapper<ErpServiceProject>().eq("user_id", custId));//.eq("check_people",0)
//            for (int i = 0; i < user_id.size(); i++) {
                user_id.parallelStream().forEach(erpServiceProject->{
//                    ErpServiceProject erpServiceProject =  user_id.get(i);
                    List<ErpProjectInService> service_project = erpProjectInServiceService.selectList(new EntityWrapper<ErpProjectInService>().eq("service_project_id", erpServiceProject.getId()));
                    if (service_project.size()>0){
                        for (int j = 0; j < service_project.size(); j++) {
                            ErpProjectInService erpProjectInService =  service_project.get(j);
                            a.add(erpProjectInService);
                        }
                    }
                        }

                );

            a.parallelStream().forEach(erpServiceProject->{
                Integer guanNumber=0;//管理用户
                Integer caoNumber=0;//操作用户
                Integer yeNumber=0;//业务用户
                Integer carNumber=0;//大车数量
//                ErpProjectInService erpServiceProject =  a.get(i);
                ErpProject erpProject = erpProjectService.selectById(erpServiceProject.getProjectId());
                if (erpProject!=null)
                    erpServiceProject.setRich(erpProject.getProjectMoney());
                else
                    erpServiceProject.setRich(0);
                switch (erpServiceProject.getProjectId()){
                    case 1:
                        guanNumber=(guanNumber+1)*erpServiceProject.getNumber();
                        caoNumber=(caoNumber+1)*erpServiceProject.getNumber();
                        yeNumber=(yeNumber+30)*erpServiceProject.getNumber();
                        carNumber=(carNumber+300)*erpServiceProject.getNumber();
                    case 2:
                        caoNumber=(caoNumber+1)*erpServiceProject.getNumber();

                    case  3:
                        caoNumber=(caoNumber+1)*erpServiceProject.getNumber();
                    case 4:
                        carNumber=(carNumber+300)*erpServiceProject.getNumber();
                    case 7:
                        guanNumber=(guanNumber+1)*erpServiceProject.getNumber();
                        caoNumber=(caoNumber+1)*erpServiceProject.getNumber();
                        carNumber=(carNumber+60)*erpServiceProject.getNumber();
                }
                erpServiceProject.setGuanNumber(guanNumber);
                erpServiceProject.setCaoNumber(caoNumber);
                erpServiceProject.setYeNumber(yeNumber);
                erpServiceProject.setCarNumber(carNumber);
                erpServiceProject.setCustCode(erpCustomer.getCusCode());
                erpServiceProject.setCustName(erpCustomer.getCusName());
                SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date=new Date();
                String format = simpleDateFormat.format(date);
                try {
                    erpServiceProject.setTime( DataUtil.TimeDifference2(format,erpServiceProject.getEndDate()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
//            for (int i = 0; i < a.size(); i++) {
//
//            }

            Result.setData(a);
             Result.setMsg("查询成功");
        }catch (Exception e ){
            e.printStackTrace();
        }
        return Result;
    }
  @RequestMapping("/selectYearss")
    @ApiOperation("系统管理-缴费统计")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
          @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpProjectInService>> selectYearss(Integer custId) {

        Result<List<ErpProjectInService>> Result=new  Result<>() ;
        try{
            ErpCustomer erpCustomer = erpCustomerService.selectById(custId);
            List<ErpProjectInService>  a=new ArrayList<>();
            List<ErpServiceProject> user_id = erpServiceProjectService.selectList(new EntityWrapper<ErpServiceProject>().eq("user_id", custId));//.eq("check_people",0)
//            for (int i = 0; i < user_id.size(); i++) {
                user_id.parallelStream().forEach(erpServiceProject->{
//                    ErpServiceProject erpServiceProject =  user_id.get(i);
                    List<ErpProjectInService> service_project = erpProjectInServiceService.selectList(new EntityWrapper<ErpProjectInService>().eq("service_project_id", erpServiceProject.getId()));
                    if (service_project.size()>0){
//                        for (int j = 0; j < service_project.size(); j++) {
                        service_project.parallelStream().forEach(erpProjectInService->{
//                            ErpProjectInService erpProjectInService =  service_project.get(j);
                            ErpProject erpProject = erpProjectService.selectById(erpProjectInService.getProjectId());
                            if (erpProject!=null){


                            erpProjectInService.setProjectName(erpProject.getProjectName());      }
                            erpProjectInService.setPayWay(erpServiceProject.getPayWay());
                            erpProjectInService.setDiscount(erpServiceProject.getDiscount());
                            erpProjectInService.setMoneyReal(erpServiceProject.getMoneyReal());
                            erpProjectInService.setCheckPeople(erpServiceProject.getCheckPeople());
                            erpProjectInService.setBz(erpServiceProject.getCheckPeople());
                            erpProjectInService.setDate(erpServiceProject.getDate());
                            erpProjectInService.setCustName(erpCustomer.getCusName());
                            erpProjectInService.setMoneySum(erpServiceProject.getMoneySum());
                            a.add(erpProjectInService);
                        });

                    }
                        }

                );

//            a.parallelStream().forEach(erpServiceProject->{
//
//              erpServiceProject.setCustName(erpCustomer.getCusName());
//
//            });
//            for (int i = 0; i < a.size(); i++) {
//
//            }

            Result.setData(a);
             Result.setMsg("查询成功");
        }catch (Exception e ){
            e.printStackTrace();
        }
        return Result;
    }

    @RequestMapping("/selectListErpServiceOrder")
    @ApiOperation("通过订单查询发票分页")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "orderNumber", value = "订单号", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpProjectInService>> selectListErpServiceOrder(String orderNumber) {
        Result<List<ErpProjectInService>> listResult = new  Result<List<ErpProjectInService>>();
        try{
            List<ErpProjectInService> order_id = erpProjectInServiceService.selectList(new EntityWrapper<ErpProjectInService>().eq("order_id", orderNumber));
            listResult.setData(order_id);
            listResult.setMsg("查询成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return  listResult;
    }
    @RequestMapping("/updateState")
    @ApiOperation("修改订单状态,订单核准,")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "orderNumber", value = "订单号", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> updateState(String orderId) {
        Result<Integer> listResult = new  Result<>();
        try{
            ErpServiceProject erpServiceProject = erpServiceProjectService.selectOne(new EntityWrapper<ErpServiceProject>().eq("order_id", orderId));
            erpServiceProject.setCheckState(1);

            listResult.setData(  erpServiceProjectService.updateById(erpServiceProject)?1:0);
            listResult.setMsg("修改成功");
        }catch (Exception e){
            listResult.setMsg("修改失败");
            e.printStackTrace();
        }
        return  listResult;
    }


    @RequestMapping("/insertInvoice")
    @ApiOperation("添加发票")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
//        @ApiImplicitParam(name = "orderNumber", value = "订单号", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<Boolean> insertInvoice(ErpInvoice erpInvoice) {
        Result<Boolean> listResult = new  Result<Boolean>();
        try{
            listResult.setData(    erpInvoiceService.insert(erpInvoice));
            listResult.setMsg("添加成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return  listResult;
    }

    @RequestMapping("/selectErpProject")
    @ApiOperation("查询服务收费表")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
//        @ApiImplicitParam(name = "orderNumber", value = "订单号", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpProject>> selectErpProject() {
        Result<List<ErpProject>>listResult = new  Result<List<ErpProject>>();
        try{
            List<ErpProject> erpProjects = erpProjectService.selectList(new EntityWrapper<ErpProject>());
//            listResult.setData(    erpInvoiceService.insert(erpInvoice));
            listResult.setData(erpProjects);
            listResult.setMsg("查询成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return  listResult;
    }
   @RequestMapping("/removeErpProject")
    @ApiOperation("删除服务收费")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
//        @ApiImplicitParam(name = "orderNumber", value = "订单号", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removeErpProject(Integer projectId) {
        Result<Integer> listResult = new  Result<Integer>();
        try{

//            listResult.setData(    erpInvoiceService.insert(erpInvoice));
            listResult.setData(  (erpProjectService.deleteById(projectId)?1:0));
            listResult.setMsg("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            listResult.setMsg("删除失败");
        }
        return  listResult;
    }



    @RequestMapping("/selectInvoice")
    @ApiOperation("查询发票分页通过起始时间和结束时间")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "startDate", value = "起始时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<Page<ErpInvoice>> selectInvoice(@RequestParam(value = "page", defaultValue = "1") int page,
                                           @RequestParam(value="limit",defaultValue="10") int limit,@RequestParam(value="limit",defaultValue="10")  String norms,
                                           @RequestParam(value="startDate",defaultValue="")String startDate,
                                           @RequestParam(value="endDate",defaultValue="") String endDate) {
        Result<Page<ErpInvoice>> result=new  Result<Page<ErpInvoice>>();
        try{
            Page<ErpInvoice> page1=new Page<ErpInvoice>(page,limit);
            Page<ErpInvoice> customer_id = erpInvoiceService.selectPage(page1, new EntityWrapper<ErpInvoice>().between("dt",startDate,endDate));
            //Page<ErpCustomerCar> page=new Page<ErpCustomerCar>(1,2);
            result.setData(customer_id);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

   @RequestMapping("/selectInvoiceById")
    @ApiOperation("查询发票通过id")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "id", value = "发票id", required = false, dataType = "String", paramType = "query")
//            @ApiImplicitParam(name = "endDate", value = "结束时间", required = false, dataType = "String", paramType = "query")
    })
    public @ResponseBody
    Result<ErpInvoice> selectInvoiceById( Integer id) {
        Result<ErpInvoice> result=new  Result<ErpInvoice>();
        try{
            ErpInvoice erpInvoice = erpInvoiceService.selectById(id);
            result.setData(erpInvoice);
            result.setMsg("查询成功");
        }catch (Exception e){e.printStackTrace();
            result.setMsg("查询失败");}
        return result;
    }

    @GetMapping("/qrPay")
    @ApiOperation(value ="扫码支付", notes="")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = false, dataType = "int"),
            @ApiImplicitParam(name = "money", value = "价格", required = false, dataType = "Double"),
            @ApiImplicitParam(name = "ordernum", value = "订单号", required = false, dataType = "String")
    })
    public void qrPay(@RequestParam("userId") int userId, @RequestParam("money") String money, HttpServletRequest request, HttpServletResponse response, String ordernum) throws WriterException, IOException {
        try {
            Map<String, String> map= WxPayUtil.QRcode(money, "车乾坤", userId, ordernum, response, request);
            if(map!=null) {
                String code_url=map.get("code_url");
                QRcodeUtil.encodeQrcode(code_url,response);
            }

        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
